<template>
  <a-modal
    :title="title"
    width="50%"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-row class="form-row" :gutter="24">
          <a-col :lg="20" :md="24" :sm="24">
            <a-form-item label="姓名" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-model="infoData.userName" placeholder="请输入姓名"/>
            </a-form-item>
          </a-col>
          <a-col :lg="20" :md="24" :sm="24">
            <a-form-item label="性别" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-model="infoData.userSex" placeholder="请输入性别"/>
            </a-form-item>
          </a-col>
          <a-col :lg="20" :md="24" :sm="24">
            <a-form-item label="部" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-model="infoData.userBranch" placeholder="请输入部"/>
            </a-form-item>
          </a-col>
          <a-col :lg="20" :md="24" :sm="24">
            <a-form-item label="教研室" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-model="infoData.userTeach" placeholder="请输入教研室"/>
            </a-form-item>
          </a-col>
          <a-col :lg="20" :md="24" :sm="24">
            <a-form-item label="职称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-model="infoData.userTitle" placeholder="请输入职称"/>
            </a-form-item>
          </a-col>
          <a-col :lg="20" :md="24" :sm="24">
            <a-form-item label="学历" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-model="infoData.userEducation" placeholder="请输入学历"/>
            </a-form-item>
          </a-col>
          <a-col :lg="20" :md="24" :sm="24">
            <a-form-item label="学位" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-model="infoData.userDegree" placeholder="请输入学位"/>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-spin>
    <template slot="footer">
      <a-button key="back" type="primary" @click="handleOk">
        保存并关闭
      </a-button>
    </template>
  </a-modal>
</template>

<script>
import { getUrl,postAxiosUrl } from '@/api/manage'
import moment from 'moment'
export default {
  components:{},
  data () {
    return {
      labelCol: { lg: { span: 5 }, sm: { span: 5 } },
      wrapperCol: { lg: { span: 19 }, sm: { span: 19 } },
      form: this.$form.createForm(this),
      title:'',
      visible: false,
      confirmLoading: false,
      infoData:{},
    }
  },
  created () {
    
  },
  methods: {
    moment,
    add () {
      this.title = '添加'
      this.visible = true
      this.infoData = {userId:'new_'+this.getUUID(),userName:'',userSex:'',userBranch:'',userTeach:'',userTitle:'',userEducation:'',userDegree:''}
    },
    edit (record) {
      this.title = '编辑'
      this.visible = true
      var _this = this
      this.infoData = {}
      _this.confirmLoading = true
      var params = {userId:record.userId}
      getUrl('userManage/getInfo', params)
        .then(res => {
          console.log(res)
           _this.infoData = res.result
          _this.confirmLoading = false
        })
    },
    handleOk(){
      var _this = this
      var params = this.infoData
      var check = this.checkParams(params)
      if(check.flg){
        _this.$message.warning(check.msg)
        return
      }
      _this.confirmLoading = true
      postAxiosUrl('userManage/save', params)
      .then(res => {
        if(res.success){
          _this.confirmLoading = false
          _this.$emit('ok', params)
          _this.visible = false
        }
      })
    },
    //{userId:'new_'+this.getUUID(),userName:'',userSex:'',userBranch:'',userTeach:'',userTitle:'',userEducation:'',userDegree:''}
    checkParams(params){
      if(!params.userName){
        var check = {flg:true,msg:'请输入姓名'}
        return check
      }
      if(!params.userSex){
        var check = {flg:true,msg:'请输入性别'}
        return check
      }
      if(!params.userBranch){
        var check = {flg:true,msg:'请输入部'}
        return check
      }
      if(!params.userTeach){
        var check = {flg:true,msg:'请输入教研室'}
        return check
      }
      if(!params.userTitle){
        var check = {flg:true,msg:'请输入职称'}
        return check
      }
      if(!params.userEducation){
        var check = {flg:true,msg:'请输入学历'}
        return check
      }
      if(!params.userDegree){
        var check = {flg:true,msg:'请输入学位'}
        return check
      }
      var check = {flg:false,msg:''}
      return check
    },
    handleCancel () {
      this.visible = false
    },
  }
}
</script>
<style>
    .ant-table-body {
      overflow: auto;
    }
    .ant-modal{
      top:10px
    }
</style>
